<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
<link href="../assets/css/bootstrap.css" rel="stylesheet" />
    <!-- FontAwesome Styles-->
    <link href="../assets/css/font-awesome.css" rel="stylesheet" />
    <link href="../css/pulic.css" rel="stylesheet"/>
    <!-- Google Fonts-->
    <link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css' />
    <!-- TABLE STYLES-->
    <link href="../assets/js/dataTables/dataTables.bootstrap.css" rel="stylesheet" />
    <script src="../js/layui/layui.js"></script>
    <script src="../js/jquery-3.2.1/jquery-3.2.1.js"></script>
    <style media="screen">
        .ECalendar{width:120px;height:30px;}
        .approvalStateNameColor{
        	color:red;
        	
        }
    </style>
</head>
<body>
<!--<div class="panel panel-default">-->

<div class="panel-heading">

</div>
<div class="row" style="margin-left: 1%;">
    <form class="form-inline" >
        <div class="form-group">
            <input type="text" class="form-control" id="exampleInputName1" placeholder="请输入名字">
        </div>
        <div class="form-group" style="margin-left: 1%;">
            <input type="text" class="form-control" id="exampleInputName2" placeholder="请输入金额"> -
            <input type="text" class="form-control" id="exampleInputName3" placeholder="请输入金额">
        </div>
        <div class="form-group" style="margin-left: 1%;">
            <input type="text" class="form-control" id="exampleInputName4" placeholder="处理状态">
        </div>
        <button type="button" class="btn btn-info" id="subBtn">搜索</button>
    </form>
</div>
<div class="panel-body">
    <div class="table-responsive">
        <table class="table table-hover">
            <thead>
            <tr>
                <th>报账人</th>
                <th>报账名称</th>
                <th>报账ID</th>
                <th>金额</th>
                <th>状态</th>
                <th>详情</th>
                <th>补单</th>
            </tr>
            </thead>
            <tbody id="search">
            
            <c:forEach items="${declarationInfoList }" var="decInfoList" varStatus="status">
             <tr class="decl" >
                <td class="popup userName">${decInfoList.userName }</td>
                <td class="popup reimbursementTypeName">${decInfoList.reimbursementTypeName }</td>
                <td class="popup reimbursementId" id="${decInfoList.reimbursementId }">${decInfoList.reimbursementId }</td>
                <td class="popup">${decInfoList.reimbursementMoney }</td>
                <c:if test="${decInfoList.approvalStateName=='同意' }">
                 <td class="approvalStateName" id="work${status.index}">${decInfoList.approvalStateName }</td>                               
                 <td><input type="submit" value="详情" class="btn btn-primary details" onclick="details(this)"></td>
                 <td><input type="submit" value="补单" class="btn btn-primary singleSupplement" onclick="singleSupplement(this)"></td>
                </c:if>
                <c:if test="${decInfoList.approvalStateName=='未同意' }">
                 <td style="color:red" id="work${status.index}">${decInfoList.approvalStateName }</td>                                
                 <td><input type="submit" value="详情" class="btn btn-primary details" onclick="details(this)"></td>
                 <td><input type="submit" value="补单" class="btn btn-primary singleSupplement" onclick="singleSupplement(this)"></td>
                </c:if>
                <c:if test="${decInfoList.approvalStateName=='驳回' }">
                 <td style="color:red" id="work${status.index}">${decInfoList.approvalStateName }</td>                                
                 <td><input type="submit" value="详情" class="btn btn-primary details" onclick="details(this)"></td>
                 <td><input type="submit" value="失效" class="btn btn-btn"></td>
                </c:if>
                <c:if test="${empty decInfoList.approvalStateName}">
                 <td id="work${status.index}">${decInfoList.approvalStateName }</td>                   
                 <td><input type="submit" value="详情" class="btn btn-primary details" onclick="details(this)"></td>
                 <td><input type="submit" value="补单" class="btn btn-primary singleSupplement" onclick="singleSupplement(this)"></td>
                </c:if>

            </tr>
            </c:forEach>
           
           
            </tbody>
        </table>
    </div>
</div>

					<!--分页功能-->
                         <div class="row" style="margin-left: 25%;margin-bottom:1%">
                   	<div class="col-sm-6">
                   		<div class="dataTables_paginate paging_simple_numbers" id="dataTables-example_paginate">
                   			<ul class="pagination">
                   				<li class="paginate_button previous" aria-controls="dataTables-example" tabindex="0" id="dataTables-example_previous">
                   					<a href="listSingMsgByStaff.do?pageNow=1">首页</a>
                   				</li>
								<li class="paginate_button " aria-controls="dataTables-example" tabindex="0">
								  <c:choose> 
								   <c:when test="${page.pageNow - 1 > 0}"> 
								    <a href="listSingMsgByStaff.do?pageNow=${page.pageNow - 1}" rel="external nofollow" >上一页</a> 
								   </c:when> 
								   <c:when test="${page.pageNow - 1 <= 0}"> 
								    <a href="listSingMsgByStaff.do?pageNow=1" rel="external nofollow" rel="external nofollow" >上一页</a> 
								   </c:when> 
								  </c:choose> 
								</li>
								<li class="paginate_button " aria-controls="dataTables-example" tabindex="0">
									<a>第 ${page.pageNow} 页</a>
								</li>
								<li class="paginate_button " aria-controls="dataTables-example" tabindex="0">
									<c:choose> 
									<c:when test="${page.totalPageCount==0}"> 
										<a href="listSingMsgByStaff.do?pageNow=${page.pageNow}" rel="external nofollow" rel="external nofollow" >下一页</a> 
									</c:when> 
									<c:when test="${page.pageNow + 1 < page.totalPageCount}"> 
									    <a href="listSingMsgByStaff.do?pageNow=${page.pageNow + 1}" rel="external nofollow" >下一页</a> 
									</c:when> 
									<c:when test="${page.pageNow + 1 >= page.totalPageCount}"> 
									    <a href="listSingMsgByStaff.do?pageNow=${page.totalPageCount}" rel="external nofollow" rel="external nofollow" >下一页</a> 
									</c:when> 
									</c:choose> 
								</li>
								<li class="paginate_button next" aria-controls="dataTables-example" tabindex="0" id="dataTables-example_next">
								  <c:choose> 
								   <c:when test="${page.totalPageCount==0}"> 
								    <a href="listSingMsgByStaff.do?pageNow=${page.pageNow}" rel="external nofollow" rel="external nofollow" >尾页</a> 
								   </c:when> 
								   <c:otherwise> 
								    <a href="listSingMsgByStaff.do?pageNow=${page.totalPageCount}" rel="external nofollow" rel="external nofollow" >尾页</a> 
								   </c:otherwise> 
								  </c:choose> 
								</li>
                   			</ul>
                   		</div>
                   	</div>
                   </div>
</body>

<script src="../assets/js/jquery-1.10.2.js"></script>
<!-- Bootstrap Js -->
<script src="../assets/js/bootstrap.min.js"></script>
<!-- Metis Menu Js -->
<script src="../assets/js/jquery.metisMenu.js"></script>
<!-- DATA TABLE SCRIPTS -->
<script src="../assets/js/dataTables/jquery.dataTables.js"></script>
<script src="../assets/js/dataTables/dataTables.bootstrap.js"></script>
<script src="../js/Ecalendar.jquery.min.js"></script>
<script>
    $(document).ready(function () {
        $('#dataTables-example').dataTable();
        
    });

    layui.use('layer', function(){
        var layer = layui.layer;
    });
    $('.popup').on('click', function(){
    	var reimbursementId = $(this).closest("tr").find(".reimbursementId").text();//报销id
    	console.log("--"+reimbursementId);
    	 layer.open({
             type: 2,
             title: '流程跟踪',
             maxmin: true,
             shadeClose: false, //点击遮罩关闭层
             area : ['80%' , '65%'],
             content: ['${pageContext.request.contextPath}/declarationInformation/listProcessMsg.do?reimbursementId='+reimbursementId+'','yes']
         });
       
    });

   
function details(thisObj){
	var reimbursementId = $(thisObj).closest("tr").find(".reimbursementId").text();//报销id
	var reimbursementTypeName = $(thisObj).closest("tr").find(".reimbursementTypeName").text(); //报销类型名
	console.log(reimbursementTypeName);
	console.log(reimbursementId);
	 layer.open({
         type: 2,
         title: '详情',
         maxmin: true,
         shadeClose: false, //点击遮罩关闭层
         area : ['80%' , '80%'],
         content: ['${pageContext.request.contextPath}/work/listWorkMsgDetails.do?reimbursementId='+reimbursementId+'&reimbursementTypeName='+reimbursementTypeName+'','yes']
     });
}
   

//点击补单 获取当前行的报销id和报销类型名
function singleSupplement(thisObj){
	var reimbursementId = $(thisObj).closest("tr").find(".reimbursementId").text();//报销id
	var reimbursementTypeName = $(thisObj).closest("tr").find(".reimbursementTypeName").text(); //报销类型名
	console.log(reimbursementId);
	console.log(reimbursementTypeName);
	layer.open({
         type: 2,
         title: '补单',
         maxmin: true,
         shadeClose: false, //点击遮罩关闭层
         area : ['80%' , '80%'],
         content: ['${pageContext.request.contextPath}/declarationInformation/listdetails.do?reimbursementId='+reimbursementId+'&reimbursementTypeName='+reimbursementTypeName+'','yes']
     });
}

//点击搜索
$("#subBtn").click(function(){
	var reimbursementTypeName = $("#exampleInputName1").val();
	var startMoney = parseInt($("#exampleInputName2").val());
	var endMoney = parseInt($("#exampleInputName3").val());//结束ine
	var approvalStateName = $("#exampleInputName4").val();//审批状态
	var GetSingMsgJson = {
			"reimbursementTypeName":reimbursementTypeName,
			"startMoney":startMoney,
			"endMoney":endMoney,
			"approvalStateName":approvalStateName,
	};
	if($("#search").html != null){
		$("#search").children().remove();
	}
	 $.ajax({
			url:"../declarationInformation/getSingMsg.do",
			type:"POST",
			contentType:'application/json;charset=UTF-8',//关键是要加上这行
	        //traditional:true,//这使json格式的字符不会被转码
	        dataType:"json",
	        async:true,
	        data:JSON.stringify(GetSingMsgJson),//把json对象转为字符串传递给后台
			success:function(data){
				$("#search");//搜索
				var str=""; 
				if(data == null){
					layer.msg("未找到响应数据，请重新输入！");
				}
				$.each(data,function(key,val){
					console.log(val);
					str += '<tr class="decl" >'+
	                '<td class="popup userName">'+val.userName+'</td>'+
	                '<td class="popup reimbursementTypeName">'+val.reimbursementTypeName+'</td>'+
	                '<td class="popup reimbursementId" id="'+val.reimbursementId+'">'+val.reimbursementId+'</td>'+
	                '<td class="popup">'+val.reimbursementMoney+'</td>';
	                if(val.approvalStateName =="未同意"){
	                	str +=  '<td style="color:red">'+val.approvalStateName+'</td>';
	                }else if(val.approvalStateName =="同意"){
	                	str +=  '<td >'+val.approvalStateName+'</td>';
	                }else{
	                	str +=  ' <td></td>';
	                }
	               
	                str += '<td><input type="submit" value="详情" class="btn btn-primary details" onclick="details(this)"></td>'+
	                '<td><input type="submit" value="补单" class="btn btn-primary singleSupplement" onclick="singleSupplement(this)"></td>'+
	           		'</tr>'; 
	           		console.log("==="+str);
				});
				$("#search").append(str);
				
				 	$("#exampleInputName1").val("");
					$("#exampleInputName2").val("");
				 	$("#exampleInputName3").val("");//
				 	$("#exampleInputName4").val("");//审批状态
			},
			error:function(data){
				layer.msg("数据错误，请重新输入！");
				
			},
	});
});

</script>
</html>